<?php
N::loadClass('N_Controller_Action');
class APP_Controller_Admin_Category extends N_Controller_Action 
{
	private $_nameFilterAllow = '/[A-Za-z0-9_\-\u4e00-\u9fa5]/';
	
	private $_nameFilterDeny;
	
	public function actionIndex()
	{
		
	}
	
	public function actionAdd()
	{
		if (!empty($_POST['go']) && $_POST['go'] == 'sure')
		{
			$name = $_POST['name'];
			$parent = intval($_POST['parent']);
			$order = intval($_POST['order']);
			if ($this->_nameFilterAllow != '' && $this->_nameFilterAllow != null)
			{
				if (!preg_grep($this->_nameFilterAllow, $name))
				{
					N::loadClass('N_Helper_Js');
					N_Helper_Js::goBack('不合法的分类名称');
					return false;
				}
			}
			if ($this->_nameFilterDeny != '' && $this->_nameFilterDeny != null)
			{
				if (preg_grep($this->_nameFilterDeny))
				{
					N::loadClass('N_Helper_Js');
					N_Helper_Js::goBack('不合法的分类名称');
					return false;
				}
			}
			if ($parent < 1)
			{
				N::loadClass('N_Helper_Js');
				N_Helper_Js::goBack('不合法的父分类ID');
				return false;
			}
			$rtn = $this->_getModel()->add($name, $parent, $order);
			$info = null;
			if ($rtn)
			{
				$info = '插入分类成功';
			}
			else 
			{
				$info = '插入分类失败,失败信息:'.$this->_getModel()->getError();
			}
			N::loadClass('N_Helper_Js');
			N_Helper_Js::goBack($info);
			return;
		}
		else 
		{
			$category = $this->_getModel()->getCategoryList();
			include('template/category_add.html');
		}
	}
	
	public function actionDelete()
	{
		
	}
	
	public function actionEdit()
	{
		
	}
}